<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false"%>
<html>
<head>
    <title>首拖件规则</title>
</head>
<body>
<div ng-app="myApp" ng-controller="MajorCtrl">

        <ui-form key="majorAdd" column="1">
            <ui-form-select-remote label="供应商:" url="system/supplier/listall" value-name="code" text-name="name" name="supplierCode"></ui-form-select-remote>
            <ui-form-select name="state" label="激活状态:" >
                <option value="0">否</option>
                <option value="1">是</option>
            </ui-form-select>
            <ui-form-select-remote   label="解析器类:" url="rule/major/parserstransform" value-name="parser"  text-name="exhibition" name="parser"></ui-form-select-remote>
            <ui-form-textarea name="description" label="规则描述:" readOnly="true" ></ui-form-textarea>
            <ui-form-textarea name="initJson" label="解析类初始化参数:"></ui-form-textarea>
        </ui-form>
</div>
<script>
    angular.module('myApp', ['ui.form']);
    angular.module('myApp').controller('MajorCtrl', function ($scope) {
        $scope.$on('ui.form.submit',function (event,param) {
            $.ajax({
                url:"rule/major/add",
                type:"post",
                data:param
            }).done(function (result) {
                if(result.code=='0000'){
                    toastr.success(result.data);
                    setTimeout(function () {
                        window.location.href="rule/major/index.html";
                    },1500);
                }else{
                    toastr.error(result.msg);
                }
            }).fail(function (err) {
                
            });
        });

        $(document).ready(function () {
            $("select[name='parser']").bind('change',function(){
                var value=this.value;
                $.ajax({
                    url:"rule/major/getinfos",
                    type:"get",
                    data:{parser:value},
                    success:function (result) {
                        var data=result.data||[];
                        var str1="";
                        var str2="";
                        for (var i in data){
                            if(data[i].parser== value){
                                str1=data[i].description;
                                str2=data[i].initJson;
                            }
                        }
                        $("textarea[name='description']").val(str1);
                        $("textarea[name='initJson']").val(str2);
                    },
                    fail:function (result) {
                        toastr.error(result.msg);
                    }
                });



            });
        });
    });
</script>
</body>
</html>
